/*
 * @Author: malgee
 * @Date: 2025-04-28 09:20:10
 * @LastEditors: maling
 * @LastEditTime: 2025-04-28 09:25:54
 * @FilePath: /vue3-ts-cms/src/hooks/use-page-modal.ts
 * @Description: 
 * 
 */
import { ref } from 'vue'
import pageModal from '@/components/page-modal'

type CallbackFn = (item?: any) => void

export function usePageModal(addCallback?: CallbackFn, editCallback?: CallbackFn) {
  const pageModelRef = ref<InstanceType<typeof pageModal>>()
  const defaultInfo = ref({})
  const handleAdd = () => {
    defaultInfo.value = {}
    if(pageModelRef.value) {
      pageModelRef.value.dialogVisible = true
    }
    addCallback?.()
  }
  const handleEdit = (item: any) => {
    defaultInfo.value = {...item}
    if(pageModelRef.value) {
      pageModelRef.value.dialogVisible = true
    }
    editCallback?.()
  }
  return [
    pageModelRef,
    defaultInfo,
    handleAdd,
    handleEdit
  ]
}